
window.onload = function (ev) {

    //登陆按钮单机
    $("#submit").click(function () {
        if (!provingParam()){
            return;
        }
        // 登录请求
        let formData = new FormData();
        formData.append("username",$("#username").val());
        formData.append("pwd",$('#pwd').val());
        formData.append("loginMethod",$('#loginMethod').val());
        axios.post("./login",formData).then(function (res) {
            console.log(res)
            const data = res.data;
            if (data.code === 1){
                // 登录成功
                window.location.href=data.uri
            }else if(data.code === 0){
                // 登录失败
                alert(data.msg);
            }
        })
    });

};

/**
 * 验证参数
 */
function provingParam() {
    let username = $("#username").val()
        ,pwd = $('#pwd').val()
    if (username === ''){
        alert("账号不能为空");
        return false;
    }else if (username.length < 4){
        alert("账号长度不能小于4位");
        return false;
    }
    if (pwd === ''){
        alert("密码不能为空");
        return false;
    }else if (pwd.length < 6){
        alert("密码长度不能小于6位");
        return false;
    }
    return true;
}